package com.ars.common.servlet.admin.material;

import com.ars.common.beans.Active.Active;
import com.ars.common.beans.Active.Mysubmit;
import com.ars.common.beans.User.User;
import com.ars.common.dao.activity.CollegeActiveMaterialMysql;
import com.ars.common.dao.activity.FindActivityById;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/ThroughOutCollegeActiveServlet")
public class ThroughOutCollegeActiveServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User logUser = (User) request.getSession().getAttribute("LogUser");
        String UserID = logUser.getUserID();
        String id = request.getParameter("id");
        ArrayList<Mysubmit> mysubmits = new ArrayList<>();
        Active active;




        System.out.println("测试学院材料导出");

        try {
            active = FindActivityById.findActivityById(id);
        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        try {
            mysubmits =  CollegeActiveMaterialMysql.findMysubmitList(UserID, Integer.parseInt(id));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        request.setAttribute("active", active);
        request.setAttribute("CollegeSubmit", mysubmits);
        request.getRequestDispatcher("admin/throughOutCollegeActive.jsp").forward(request, response);
    }
}
